package com.ruoyi.web.controller.applet;

import java.util.List;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.applet.domain.MiniProductBrand;
import com.ruoyi.applet.service.IMiniProductBrandService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 产品品牌Controller
 *
 * @author liucan
 * @date 2024-04-02
 */
@RestController
@RequestMapping("/applet/productBrand")
public class MiniProductBrandController extends BaseController {
    @Resource
    private IMiniProductBrandService miniProductBrandService;

    @Resource
    private MiniLeagueController miniLeagueController;

    /**
     * 查询产品品牌列表
     */
    @GetMapping("/list")
    public TableDataInfo list(MiniProductBrand miniProductBrand, HttpServletRequest request) {
        startPage();
        miniProductBrand.setToApplet(miniLeagueController.toApplet(request));
        List<MiniProductBrand> list = miniProductBrandService.selectMiniProductBrandList(miniProductBrand);
        return getDataTable(list,null);
    }

    /**
     * 小程序商城和报价显示产品品牌用到的接口
     */
    @GetMapping("/miniSelect")
    public AjaxResult miniSelect(MiniProductBrand miniProductBrand, HttpServletRequest request) {
        miniProductBrand.setToApplet(miniLeagueController.toApplet(request));
        List<MiniProductBrand> list = miniProductBrandService.miniSelect(miniProductBrand);
        return AjaxResult.success(list);
    }

    /**
     * 导出产品品牌列表
     */
    @Log(title = "产品品牌", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MiniProductBrand miniProductBrand) {
        List<MiniProductBrand> list = miniProductBrandService.selectMiniProductBrandList(miniProductBrand);
        ExcelUtil<MiniProductBrand> util = new ExcelUtil<MiniProductBrand>(MiniProductBrand.class);
        util.exportExcel(response, list, "产品品牌数据");
    }

    /**
     * 获取产品品牌详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(miniProductBrandService.selectMiniProductBrandById(id));
    }

    /**
     * 新增产品品牌
     */
    @Log(title = "产品品牌", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MiniProductBrand miniProductBrand, HttpServletRequest request) {
        miniProductBrand.setToApplet(miniLeagueController.toApplet(request));
        return toAjax(miniProductBrandService.insertMiniProductBrand(miniProductBrand));
    }

    /**
     * 修改产品品牌
     */
    @Log(title = "产品品牌", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MiniProductBrand miniProductBrand, HttpServletRequest request) {
        miniProductBrand.setToApplet(miniLeagueController.toApplet(request));
        return toAjax(miniProductBrandService.updateMiniProductBrand(miniProductBrand));
    }

    /**
     * 删除产品品牌
     */
    @Log(title = "产品品牌", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(miniProductBrandService.deleteMiniProductBrandByIds(ids));
    }
}
